package com.example.security.handle;

import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;

/**
 * @application:
 * @author: LiYuhang
 * @Date: 2021/5/29 20:55
 * @version: 0.1
 * @Description :
 * @Modified By:
 */
public interface ResponseMsg {

    public static void  response(HttpServletResponse res,Consumer<Map> consumer) throws IOException {
        res.setContentType("application/json;charset=utf-8");
        PrintWriter out = res.getWriter();
        Map<String, Object> map = new HashMap<>();
        consumer.accept(map);
        out.write(new ObjectMapper().writeValueAsString(map));
        out.flush();
        out.close();
    }
}
